
package demo.issuetracker.controller;

import demo.issuetracker.model.CustomIdentity;
import demo.issuetracker.entity.User;
import demo.issuetracker.entity.Issue;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.In;

import org.jboss.seam.annotations.web.RequestParameter;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIData;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
import javax.faces.validator.ValidatorException;
import java.util.Map;
import java.util.List;
import demo.issuetracker.entity.UploadedFile;
import java.util.ArrayList;
import org.richfaces.model.UploadItem;



/**
 * Glue code to bind Edit Issue Service with the view framework (Seam). This class contains
 * a default implementation of the action methods. Please avoid reimplmenting the action methods in this class.
 * The purpose of this class is to declare properties which can be bound to the UI.
 * 
  * This page allows the user to modify an existing issue.
  *
 * Automatically generated by clickframes
 * 
 * @author Vineet Manohar
 */
public abstract class GeneratedEditIssueController extends Controller {
    @In("#{issueDao}") 
    protected demo.issuetracker.dao.IssueDao issueDao;

    @In("#{issueService}") 
    protected demo.issuetracker.entity.service.IssueService issueService;


    public User getLoggedInUser() {
        return identity.getUser();
    }



    /** $!Issue - PARAM_PRIMARY_KEY */
    protected Issue issue;

    /** 
     * Get Issue
     *  
     * @return Issue
     */
    public Issue getIssue() {
       return this.issue;
    }

    /**
     * Set Issue
     *
     * @param issue
     */
    public void setIssue(Issue issue) {
        this.issue = issue;
    }


    protected void initIssue() {
        // if ${outputList.id} has not been initialized, initialize it now
        if (getIssue() == null) {
            setIssue(loadIssue());
        }
        
        // updating all linked entities here
        if (getIssue() != null) {
            // This entity is of type 'issue'. There is a form on this page which 
            // updates an entity of type 'issue'. Therefore, use this entity to prePopulate the inputs
            setEditIssueFormIssueTitle(getIssue().getTitle());
             setEditIssueFormDescription(getIssue().getDescription());
             setEditIssueFormPriority(getIssue().getPriority());
             setEditIssueFormOwner(getIssue().getAssignee());
             setEditIssueFormEnvironment(getIssue().getEnvironment());
             // setEditIssueFormAttachment(getIssue().getAttachment().clone());
         }
     }

    protected Issue loadIssue() {
        return issueDao.findByPrimaryKey(issueId);
    }

    protected void reloadIssue() {
        clearIssue();
        loadIssue();
    }

    protected void clearIssue() {
        setIssue(null);
    }
 
    
	@SuppressWarnings("unused")
	private static final Log logger = LogFactory.getLog(GeneratedEditIssueController.class);

	@In
	protected CustomIdentity identity;

    @Create
    public void init() {


        // initialize all file inputs
 
        initEditIssueFormPriority();
        initEditIssueFormOwner();
        initEditIssueFormEnvironment();

        // initialize all file inputs
        // editIssueFormAttachment = new UploadedFile();
          // all inputs initialized here 
    }

	@RequestParameter


    /** $!Unique identifier of issue to be modified. */
    private String issueId;

    /** 
     * Get Issue ID
     *  
     * @return Issue ID
     */
    public String getIssueId() {
       return this.issueId;
    }

    /**
     * Set Issue ID
     *
     * @param issueId
     */
    public void setIssueId(String issueId) {
        this.issueId = issueId;
    }




	/**
	 * This method should be called before the page is loaded
	 * 
	 * All the page parameters should be consumed in this method
	 */    
    public String processPageParameters() {
        initIssue();


          // if you need to add more code, override this method in the child class

        return null;
    }

 



	/** Issue Title
	 *
 	 * Issue Title
 	 */
   
	protected String editIssueFormIssueTitle;

  	@org.hibernate.validator.NotNull(message="Please enter an issue title.")
  	public String getEditIssueFormIssueTitle() {
	   return this.editIssueFormIssueTitle;
	}

	public void setEditIssueFormIssueTitle(String editIssueFormIssueTitle) {
		this.editIssueFormIssueTitle = editIssueFormIssueTitle;
	}
	/** Description
	 *
 	 * Description
 	 */
   
	protected String editIssueFormDescription;

  	@org.hibernate.validator.NotNull(message="Please enter a description for your issue.")
  	public String getEditIssueFormDescription() {
	   return this.editIssueFormDescription;
	}

	public void setEditIssueFormDescription(String editIssueFormDescription) {
		this.editIssueFormDescription = editIssueFormDescription;
	}




    /** $!${input.description} */
    private UploadedFile editIssueFormAttachment;

    /** 
     * Get Attachment
     *  
     * @return Attachment
     */
    public UploadedFile getEditIssueFormAttachment() {
       return this.editIssueFormAttachment;
    }

    /**
     * Set Attachment
     *
     * @param editIssueFormAttachment
     */
    public void setEditIssueFormAttachment(UploadedFile editIssueFormAttachment) {
        this.editIssueFormAttachment = editIssueFormAttachment;
    }



    /** $!${input.description} Data */
    private java.io.InputStream editIssueFormAttachmentInputStream;

    /** 
     * Get Attachment Data
     *  
     * @return Attachment Data
     */
    public java.io.InputStream getEditIssueFormAttachmentInputStream() {
       return this.editIssueFormAttachmentInputStream;
    }

    /**
     * Set Attachment Data
     *
     * @param editIssueFormAttachmentInputStream
     */
    public void setEditIssueFormAttachmentInputStream(java.io.InputStream editIssueFormAttachmentInputStream) {
        this.editIssueFormAttachmentInputStream = editIssueFormAttachmentInputStream;
    }



    /** $!${input.description} ContentType */
    private String editIssueFormAttachmentContentType;

    /** 
     * Get Attachment ContentType
     *  
     * @return Attachment ContentType
     */
    public String getEditIssueFormAttachmentContentType() {
       return this.editIssueFormAttachmentContentType;
    }

    /**
     * Set Attachment ContentType
     *
     * @param editIssueFormAttachmentContentType
     */
    public void setEditIssueFormAttachmentContentType(String editIssueFormAttachmentContentType) {
        this.editIssueFormAttachmentContentType = editIssueFormAttachmentContentType;
    }



    /** $!${input.description} File name of uploaded file */
    private String editIssueFormAttachmentFileName;

    /** 
     * Get Attachment File name
     *  
     * @return Attachment File name
     */
    public String getEditIssueFormAttachmentFileName() {
       return this.editIssueFormAttachmentFileName;
    }

    /**
     * Set Attachment File name
     *
     * @param editIssueFormAttachmentFileName
     */
    public void setEditIssueFormAttachmentFileName(String editIssueFormAttachmentFileName) {
        this.editIssueFormAttachmentFileName = editIssueFormAttachmentFileName;
    }


    protected void initEditIssueFormPriority() {
        this.editIssueFormPriorityOptions.add(new SelectItem("high", "High"));
        this.editIssueFormPriorityOptions.add(new SelectItem("normal", "Normal"));
        this.editIssueFormPriorityOptions.add(new SelectItem("low", "Low"));
    }

 /** Priority
  *
  *  Priority 
      */
  protected String editIssueFormPriority;
  
  public String getEditIssueFormPriority() {
    return this.editIssueFormPriority;
  }

  public void setEditIssueFormPriority(String editIssueFormPriority) {
    this.editIssueFormPriority = editIssueFormPriority;
  }

  protected List<SelectItem> editIssueFormPriorityOptions = new ArrayList<SelectItem>();

  public List<SelectItem> getEditIssueFormPriorityOptions() {
    return this.editIssueFormPriorityOptions;
  }

  public void setEditIssueFormPriorityOptions(List<SelectItem> editIssueFormPriorityOptions) {
    this.editIssueFormPriorityOptions = editIssueFormPriorityOptions;
  }
    protected void initEditIssueFormOwner() {
        this.editIssueFormOwnerOptions.add(new SelectItem("jonathan", "Jon"));
        this.editIssueFormOwnerOptions.add(new SelectItem("steven", "Steven"));
        this.editIssueFormOwnerOptions.add(new SelectItem("evan", "Evan"));
        this.editIssueFormOwnerOptions.add(new SelectItem("nicole", "Nicole"));
        this.editIssueFormOwnerOptions.add(new SelectItem("vineet", "Vineet"));
        this.editIssueFormOwnerOptions.add(new SelectItem("will", "Will"));
    }

 /** Assignee
  *
  *   */
  protected String editIssueFormOwner;
  
  public String getEditIssueFormOwner() {
    return this.editIssueFormOwner;
  }

  public void setEditIssueFormOwner(String editIssueFormOwner) {
    this.editIssueFormOwner = editIssueFormOwner;
  }

  protected List<SelectItem> editIssueFormOwnerOptions = new ArrayList<SelectItem>();

  public List<SelectItem> getEditIssueFormOwnerOptions() {
    return this.editIssueFormOwnerOptions;
  }

  public void setEditIssueFormOwnerOptions(List<SelectItem> editIssueFormOwnerOptions) {
    this.editIssueFormOwnerOptions = editIssueFormOwnerOptions;
  }
    protected void initEditIssueFormEnvironment() {
        this.editIssueFormEnvironmentOptions.add(new SelectItem("prod", "Production"));
        this.editIssueFormEnvironmentOptions.add(new SelectItem("test", "Testing"));
        this.editIssueFormEnvironmentOptions.add(new SelectItem("dev", "Development"));
    }

 /** Environment
  *
  *   */
  protected String editIssueFormEnvironment;
  
  public String getEditIssueFormEnvironment() {
    return this.editIssueFormEnvironment;
  }

  public void setEditIssueFormEnvironment(String editIssueFormEnvironment) {
    this.editIssueFormEnvironment = editIssueFormEnvironment;
  }

  protected List<SelectItem> editIssueFormEnvironmentOptions = new ArrayList<SelectItem>();

  public List<SelectItem> getEditIssueFormEnvironmentOptions() {
    return this.editIssueFormEnvironmentOptions;
  }

  public void setEditIssueFormEnvironmentOptions(List<SelectItem> editIssueFormEnvironmentOptions) {
    this.editIssueFormEnvironmentOptions = editIssueFormEnvironmentOptions;
  }
 
       public void editIssueFormIssueTitleValidator(javax.faces.context.FacesContext facesContext,
            javax.faces.component.UIComponent component, java.lang.Object value) {
        String valueStr = value.toString();
        
    }
     public void editIssueFormDescriptionValidator(javax.faces.context.FacesContext facesContext,
            javax.faces.component.UIComponent component, java.lang.Object value) {
        String valueStr = value.toString();
        
    }
     public void editIssueFormPriorityValidator(javax.faces.context.FacesContext facesContext,
            javax.faces.component.UIComponent component, java.lang.Object value) {
        String valueStr = value.toString();
        
    }
     public void editIssueFormOwnerValidator(javax.faces.context.FacesContext facesContext,
            javax.faces.component.UIComponent component, java.lang.Object value) {
        String valueStr = value.toString();
        
    }
     public void editIssueFormEnvironmentValidator(javax.faces.context.FacesContext facesContext,
            javax.faces.component.UIComponent component, java.lang.Object value) {
        String valueStr = value.toString();
        
    }
     public void editIssueFormAttachmentValidator(javax.faces.context.FacesContext facesContext,
            javax.faces.component.UIComponent component, java.lang.Object value) {
        String valueStr = value.toString();
        
    }

 

 
    /**
     *  Converts any form inputs bound to entities to entities, stores them in the map ready to 
     *  be passed to the service methods
     */
    protected Issue getEditIssueFormIssue() {
 
        issue.setTitle(toText(editIssueFormIssueTitle));
        issue.setDescription(toText(editIssueFormDescription));
        issue.setPriority(toText(editIssueFormPriority));
        issue.setAssignee(toText(editIssueFormOwner));
        issue.setEnvironment(toText(editIssueFormEnvironment));
        issue.getAttachment().update(editIssueFormAttachmentFileName, editIssueFormAttachmentContentType, editIssueFormAttachmentInputStream);
        return issue;
    }

 
   /**
    * Update Issue
    *
    *     * Automatically generated by clickframes
    */
   public abstract EditIssueFormUpdateIssueOutcome editIssueFormUpdateIssue();




    private static final long serialVersionUID = 1L;

     /**
     * different legal outcomes for Update Issue 
     * 
     * This page allows the user to modify an existing issue.
     */
     public enum EditIssueFormUpdateIssueOutcome {
        /** 
         * Issue Saved
         */ 
        issueUpdated    
    }
  }// clickframes::version=3339618142::clickframes